home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / simplesp.pit / simplespeech source.pit / simplespeech.c < prev   
Encoding:
C/C++ Source or Header  |  1986-02-19  |  7.3 KB  |  315 lines

  1. /*
  2.  *    Simplespeech.c - A sample speech program written in Megamax C
  3.  *    using Apple's MacinTalk speech driver.
  4.  *    I use the SimpleTools package for menus and DA handling.
  5.  *    
  6.  *    I use the strange kludge in chat.c because I found that I could not
  7.  *    call speechon,then speechoff,then speechon again. I tried to, and got
  8.  *    a "deep-shit" error and entered macsbug. Consequently, I kludged chat.c
  9.  *    to keep my speech segment separate from the main program.
  10.  *    
  11.  *    I hope you don't mind the 'bad' code I write. My philosophy is :-
  12.  *    "If it works, use it until it doesn't - then hack at it until it does..."
  13.  *
  14.  *
  15.  *    I hope you can get something out of it.
  16.  *
  17.  *
  18.  *    Jason Haines             ISD: +61 2 73-4444
  19.  *    ElecEng Undergraduate    STD:  (02) 73-4444
  20.  *    73 Davidson Avenue      ARPA: munnari!ipso!runx.oz!baron@SEISMO
  21.  *    Concord NSW 2137        UUCP: seismo!munnari!basser!ipso!runx!baron
  22.  *    AUSTRALIA                ACS: baron@runx
  23.  *
  24.  */
  25.  
  26. #include "stdio.h"
  27. #include "speech.h"
  28. #include <qd.h>
  29. #include <qdvars.h>
  30. #include <misc.h>
  31. #include <event.h>
  32. #include <pack.h>
  33. #include <win.h>
  34. #include <seg.h>
  35. #include <res.h>
  36. #include <chat.h>
  37. #include <font.h>
  38. #include <dialog.h>
  39. #include <toolbox.h>
  40. /* #include <general.h> */
  41. char *null[] = { 0 };
  42.  
  43. /* SimpleTools Declarations */
  44.  
  45. #define itemdisable    0L
  46. #define itemenable    1L
  47. #define itemcheck    2L
  48. #define itemuncheck    3L
  49. extern char applestring[];
  50. extern windowptr windowpoint();
  51. extern int wprocid;
  52. extern int dogoaway;
  53. extern int windmenu;
  54.  
  55. /* End of SimpleTools Declarations */
  56.  
  57. /* MacinTalk Declarations */
  58.  
  59. speechhandle thespeech;
  60. #define DEFPITCH    110
  61. #define DEFRATE        140
  62.  
  63. /* End of MacinTalk Declarations */
  64.  
  65. /* Dialog Defs */
  66. #define SAYITEM        1
  67. #define CANCELITEM    2
  68. #define OKITEM        2
  69. #define OKITEM2        2
  70. #define OKITEM3        1
  71. #define MOREITEM    3
  72. #define SAYTEXTITEM    3
  73. /* End of Dialog Defs */
  74.  
  75. char str[256], infilename[256];
  76. int c, err;
  77. FILE *input_file,  *fopen();
  78. int i = 0;
  79. int voicemode, voicepitch, voicerate;
  80. rect therect;
  81. dialogptr mydialogptr, aboutdialogptr, about2dialogptr, about3dialogptr;
  82. int itemtype,myitemhit;
  83. handle itemhandle;
  84. rect disprect;
  85. char speechstr[256];
  86.  
  87. #define TRUE        1
  88. #define FALSE        0
  89. #define WXORIGIN1    50
  90. #define WYORIGIN1    50
  91. #define WIDTH1        400
  92. #define HEIGHT1        250
  93. #define WXORIGIN2    50
  94. #define WYORIGIN2    50
  95. #define WIDTH2        400
  96. #define HEIGHT2        250
  97.  
  98.  
  99. exit_to_other()
  100. {
  101.     transfer(null);
  102. }
  103.  
  104.  
  105. exit_to_shell()
  106. {
  107.     chat("",voicemode,voicepitch,voicerate,LAST_CALL);
  108.     exittoshell();
  109. }
  110.  
  111. nop()
  112. {
  113. }
  114.  
  115. set_pitch()
  116. {
  117.     int err, tmp;
  118.     char answer[255];
  119.     
  120.     answer[0] = '\0';
  121.     if (err = prompt("Enter the baseline pitch in Hertz",answer))
  122.     {
  123.         tmp = atoi(answer);
  124.         if ((tmp < 69) || (tmp > 450))
  125.             alert(23288);
  126.         else
  127.         {
  128.             voicepitch = tmp;
  129.             speechpitch(thespeech,voicepitch,(short)voicemode);
  130.             menu("Speech","Reset to defaults^4",itemenable);
  131.         }
  132.     }
  133. }
  134.  
  135. set_rate()
  136. {
  137.     int err, tmp;
  138.     char answer[255];
  139.     
  140.     answer[0] = '\0';
  141.     if (err = prompt("Enter word rate in words per minute",answer))
  142.     {
  143.         tmp = atoi(answer);
  144.         if ((tmp < 85) || (tmp > 425))
  145.             alert(708);
  146.         else
  147.         {
  148.             voicerate = tmp;
  149.             speechrate(thespeech,voicerate);
  150.             menu("Speech","Reset to defaults^4",itemenable);
  151.         }
  152.     }
  153. }
  154.  
  155. set_natural_mode()
  156. {
  157.     voicemode = natural;
  158.     menu("Speech","Robotic Speech",itemuncheck);
  159.     menu("Speech","Natural Speech",itemcheck);
  160.     menu("Speech","Reset to defaults^4",itemenable);
  161. }
  162.  
  163. set_robotic_mode()
  164. {
  165.     voicemode = robotic;
  166.     menu("Speech","Robotic Speech",itemcheck);
  167.     menu("Speech","Natural Speech",itemuncheck);
  168.     menu("Speech","Reset to defaults^4",itemenable);
  169. }
  170.  
  171. reset_settings()
  172. {
  173.     voicemode = natural;
  174.     menu("Speech","Robotic Speech",itemuncheck);
  175.     menu("Speech","Natural Speech",itemcheck);
  176.     voicepitch = DEFPITCH;
  177.     voicerate = DEFRATE;
  178.     menu("Speech","Reset to defaults^4",itemdisable);
  179. }
  180.  
  181. enter_speech()
  182. {
  183.     showwindow(mydialogptr);
  184.     drawdialog(mydialogptr);
  185.     chat("Go ahead, bash the keebord",voicemode,voicepitch,voicerate,NORMAL_CALL);
  186.     do
  187.     {
  188.         modaldialog(NULL,&myitemhit);
  189.         if (myitemhit == SAYITEM)
  190.         {
  191.             getditem(mydialogptr,SAYTEXTITEM,&itemtype,&itemhandle,&disprect);
  192.             getitext(itemhandle,&speechstr);
  193.             chat(speechstr,voicemode,voicepitch,voicerate,NORMAL_CALL);
  194.         }
  195.     } while (myitemhit != CANCELITEM);
  196.     hidewindow(mydialogptr);
  197. }
  198.  
  199.  
  200. tell_about_me()
  201. {
  202.     int itemhit;
  203.     
  204.     showwindow(aboutdialogptr);
  205.     drawdialog(aboutdialogptr);
  206.     chat("Hello, I am Simple Speech, a sample speech program written in Cee using Apples Mackin Talk speech driver",voicemode,voicepitch,voicerate,NORMAL_CALL);
  207.     chat("written by Jayson Haines, copy rite 9teen atee6.",voicemode,voicepitch,voicerate,NORMAL_CALL);
  208.     chat("For more info, just hit the button.",voicemode,voicepitch,voicerate,NORMAL_CALL);
  209.     do
  210.     {
  211.         modaldialog(NULL,&itemhit);
  212.     } while ((itemhit != OKITEM) && (itemhit != MOREITEM));
  213.     hidewindow(aboutdialogptr);
  214.     if (itemhit == MOREITEM)
  215.     {
  216.         showwindow(about2dialogptr);
  217.         drawdialog(about2dialogptr);
  218.         chat("I am a giftware program, so you do not need to pay enee money to enn joy mee.",voicemode,voicepitch,voicerate,NORMAL_CALL);
  219.         chat("If u like mee, keep mee. But, do not sell me..",voicemode,voicepitch,voicerate,NORMAL_CALL);
  220.         do
  221.         {
  222.             modaldialog(NULL,&itemhit);
  223.         } while (itemhit != OKITEM2);
  224.         hidewindow(about2dialogptr);
  225.     }
  226.     showwindow(about3dialogptr);
  227.     drawdialog(about3dialogptr);
  228.     do
  229.     {
  230.         modaldialog(NULL,&itemhit);
  231.     } while (itemhit != OKITEM3);
  232.     hidewindow(about3dialogptr);
  233. }
  234.  
  235.  
  236. speak_file()
  237. {
  238.     char messagestr[256];
  239.     
  240.     if (!(err = getfile("TEXT",infilename)))
  241.         return(0);
  242.     if ((input_file = fopen (infilename, "r")) == NULL)
  243.     {
  244.         alert(1998);
  245.         return(0);
  246.     }
  247.     /* SYNTAX: chat(string,mode,pitch,rateint,chatstat) */
  248.     while ( (c = getc(input_file)) != EOF )
  249.     {
  250.         if (c=='\n')
  251.         {
  252.             str[i] = '\0';
  253.             if (i>0)
  254.                 chat(str,voicemode,voicepitch,voicerate,NORMAL_CALL);
  255.             i = 0;
  256.         }
  257.         else
  258.             str[i++] = c;
  259.     }
  260. }
  261.  
  262. menusetup()
  263. {
  264.     menu (applestring,"About SimpleSpeech^1╔",tell_about_me);
  265.     menu (applestring,"About SimpleSpeech^1╔",itemenable);
  266.     menu("File","Open Speech File/O^2",speak_file);
  267.     menu("File","Open Speech File/O^2",itemenable);
  268.     menu("File","Transfer╔^7",exit_to_other);
  269.     menu("File","(-",nop);
  270.     menu("File","Quit/Q",exit_to_shell);
  271.     menu("Edit","Undo",nop);
  272.     menu("Edit","Undo",itemdisable);
  273.     menu("Edit","Copy/C",nop);
  274.     menu("Edit","Copy/C",itemdisable);
  275.     menu("Edit","Cut/X",nop);
  276.     menu("Edit","Cut/X",itemdisable);
  277.     menu("Edit","Paste/V",nop);
  278.     menu("Edit","Paste/V",itemdisable);
  279.     menu("Edit","Clear",nop);
  280.     menu("Edit","Clear",itemdisable);
  281.     menu("Speech","Enter some words of wisdom^3",enter_speech);
  282.     menu("Speech","Enter some words of wisdom^3",itemenable);
  283.     menu("Speech","Set Pitch",set_pitch);
  284.     menu("Speech","Set Pitch",itemenable);
  285.     menu("Speech","Set Rate",set_rate);
  286.     menu("Speech","Set Rate",itemenable);
  287.     menu("Speech","Reset to defaults^4",reset_settings);
  288.     menu("Speech","Reset to defaults^4",itemdisable);
  289.     menu("Speech","Robotic Speech",set_robotic_mode);
  290.     menu("Speech","Robotic Speech",itemuncheck);
  291.     menu("Speech","Natural Speech",set_natural_mode);
  292.     menu("Speech","Natural Speech",itemcheck);
  293. }
  294.  
  295. windowsetup()
  296. {
  297. }
  298.  
  299.  
  300. main()
  301. {
  302.     simpletools("About SimpleSpeech^1╔");
  303.     menusetup();
  304.     windowsetup();
  305.     voicepitch = DEFPITCH;
  306.     voicerate = DEFRATE;
  307.     voicemode = natural;
  308.     chat("",voicemode,voicepitch,voicerate,FIRST_CALL);
  309.     mydialogptr = getnewdialog(21200,NULL,(windowptr) -1);
  310.     aboutdialogptr = getnewdialog(21201,NULL,(windowptr) -1);
  311.     about2dialogptr = getnewdialog(21202,NULL,(windowptr) -1);
  312.     about3dialogptr = getnewdialog(18165,NULL,(windowptr) -1);
  313.     for (;;) simpleevents();
  314. }
  315.